<?php
// +----------------------------------------------------------------------
// | Desc: [ Better-资金来源 ]
// +----------------------------------------------------------------------
// | Author: huangzhen_20210406
// +----------------------------------------------------------------------

namespace app\common\model;
use think\facade\Db;
class FundSource extends Common
{
    /**
     * 返回layui的table所需要的格式
     * @param $post
     * @param $user_id
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function tableDataAdmin($post)
    {
        $list_rows  = $post['limit'] ?? config('paginate.list_rows');
        $page       = $post['page'] ?? config('paginate.page');

        $where =[];
        if(isset($post['account_name']) && !empty($post['account_name'])){
            $where[] = ['account_name', 'like', '%'.$post['account_name'].'%'];
        }
        $list = $this::where($where)
                ->order('ctime desc')
                ->paginate(['list_rows' => $list_rows, 'page' => $page])
                ->toArray();
        return $result = [
            'code'  => 0,
            'msg'   => lang('get info success'),
            'data'  => $list['data'],
            'count' => $list['total'],
        ];
    }

    public function fundEdit($type, $data)
    {
        $result = [];
        switch ($type){
            case 'add':
                $result = $this->save($data + ['ctime' => getUtcTime()]);
                break;
            case 'edit':
                $id = $data['id'];
                unset($data['id'] , $data['file'] , $data['__token__']);
                $result = $this->where(['id' => $id])->update($data);
//                dd($this->getLastSql());
                break;
            case 'del':
                $result = $this->where($data)->delete();
                break;
        }
        return $result;
    }

    //---------------------------------------------前端---------------------------------------------------------------
}